﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
	xmlns:local="clr-namespace:Feedbook"
	xmlns:views="clr-namespace:Feedbook.Views"
    xmlns:auto="clr-namespace:Feedbook.Automation"
	xmlns:Feedbook_Model="clr-namespace:Feedbook.Model"
	mc:Ignorable="d"
	x:Class="Feedbook.Views.RSSReader"
    x:ClassModifier="internal"
	x:Name="Page"
	FlowDirection="LeftToRight" d:DesignWidth="658.91" d:DesignHeight="417">
    <UserControl.Resources>

        <Feedbook_Model:Feed x:Key="FeedDataSource" d:IsDataSource="True"/>

        <auto:DateTimeToOutlookStyleGroupConverter x:Key="DateTimeToOutlookStyleGroupConverter"/>

        <CollectionViewSource x:Key="ChannelSource" Source="{x:Static local:DataStore.Channels}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Title.ToPlainText"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <CollectionViewSource x:Key="CategorySource">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Category"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <DataTemplate x:Key="ChannelTemplate">
            <StackPanel x:Name="panel"  Orientation="Vertical" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top" d:DesignWidth="121.46" d:DesignHeight="35.96">
                <Grid x:Name="Grid" Height="Auto" Margin="6,0">
                    <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Title.ToPlainText}" Foreground="{DynamicResource ContrastBrush}" TextTrimming="CharacterEllipsis" Height="Auto" Margin="0">
            			<TextBlock.ToolTip>
            				<StackPanel Orientation="Horizontal">
            					<TextBlock Text="{Binding NewFeedCount}"/>
            					<TextBlock Text=" feeds downloaded ..."/>
            				</StackPanel>                
            			</TextBlock.ToolTip>
            		</TextBlock>
                    <Button x:Name="ChannelSettingButton" HorizontalAlignment="Right" VerticalAlignment="Top" Template="{DynamicResource TransparentFBButtonTemplate}" Padding="1" Margin="0,2,0,0" Height="Auto" Cursor="Hand" Click="ChannelSettingButton_Click" Opacity="0">
                        <Image Height="15" Source="/Feedbook;component/Images/Tools-Icon.png" Stretch="Fill" Width="15" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"/>
                    </Button>
                </Grid>
                <Border BorderBrush="White" BorderThickness="0,0,0,1" Height="2" Background="Black" Margin="5,10" Opacity="0.295"/>
            </StackPanel>
            <DataTemplate.Triggers>
                <EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="Grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="1" Duration="0:0:0.3" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ChannelSettingButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="UIElement.MouseLeave" SourceName="Grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="0" Duration="0:0:0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ChannelSettingButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate x:Key="CategoryFeedTemplate">
            <StackPanel x:Name="panel"  Orientation="Vertical" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top" d:DesignWidth="121.46" d:DesignHeight="35.96" MaxWidth="146">
                <Grid x:Name="grid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock  Text="{Binding Category}" Foreground="{DynamicResource ContrastBrush}" TextTrimming="CharacterEllipsis" TextWrapping="WrapWithOverflow" Grid.ColumnSpan="2" />
                    <Button x:Name="AddButton" d:LayoutOverrides="Height" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Template="{DynamicResource TransparentFBButtonTemplate}" Opacity="0" Margin="2,2,10,2" Click="AddButton_Click" Cursor="Hand">
                        <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="Ë" FontFamily="Wingdings 2" VerticalAlignment="Center" Foreground="{DynamicResource ContrastBrush}" FontSize="16"/>
                    </Button>
                </Grid>
                <Border BorderBrush="White" BorderThickness="0,0,0,1" Height="2" Background="Black" Margin="5,10" Opacity="0.295"/>
            </StackPanel>
            <DataTemplate.Triggers>
                <EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="1" Duration="0:0:0.3" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="AddButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="UIElement.MouseLeave" SourceName="grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="0" Duration="0:0:0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="AddButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate x:Key="FavoriteFeedTemplate">
            <StackPanel x:Name="panel"  Orientation="Vertical" Width="146" HorizontalAlignment="Left" VerticalAlignment="Top" d:DesignWidth="121.46" d:DesignHeight="35.96">
                <Grid x:Name="grid" Background="Transparent">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock  Text="{Binding Category}" Foreground="{DynamicResource ContrastBrush}" TextWrapping="WrapWithOverflow" TextTrimming="CharacterEllipsis" Grid.ColumnSpan="2" />
                    <Button x:Name="RemoveButton" Opacity="0" d:LayoutOverrides="Height" Template="{DynamicResource TransparentFBButtonTemplate}" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2,2,10,2" Click="RemoveButton_Click" Cursor="Hand">
                        <TextBlock Margin="0" TextWrapping="Wrap" Text="Ò" FontFamily="Wingdings 2" Foreground="{DynamicResource ContrastBrush}" FontSize="16"/>
                    </Button>
                </Grid>
                <Border BorderBrush="White" BorderThickness="0,0,0,1" Height="2" Background="Black" Margin="5,10" Opacity="0.295"/>
            </StackPanel>
            <DataTemplate.Triggers>
                <EventTrigger RoutedEvent="UIElement.MouseEnter" SourceName="grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="1" Duration="0:0:0.3" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="RemoveButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                <EventTrigger RoutedEvent="UIElement.MouseLeave" SourceName="grid">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation To="0" Duration="0:0:0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="RemoveButton"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <LinearGradientBrush x:Key="FeedLightTitleBrush2" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFC8C8C8" Offset="1"/>
            <GradientStop Color="#FFD4D4D4"/>
            <GradientStop Color="#FFB6B6B6" Offset="0.956"/>
        </LinearGradientBrush>

        <DataTemplate x:Key="FeedTitleTemplate">
            <Grid Name="grid" d:DesignWidth="250" d:DesignHeight="19" ToolTip="{Binding Title}" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Name="AttachmentImage" HorizontalAlignment="Left" Width="19" Source="/Feedbook;component/Images/podcast.png" RenderTransformOrigin="0.5,0.5" Height="Auto" VerticalAlignment="Top"/>
                <Image Source="/Feedbook;component/Images/download.png" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Width="13" Visibility="{Binding IsPodcastDownloading, Converter={StaticResource BoolToVisibilityConverter}}" Margin="6,5,2,0"/>
                <TextBlock Name="tbTitle" Grid.Column="1" Text="{Binding Title}" TextWrapping="WrapWithOverflow" FontWeight="Bold" TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch" Height="19" Margin="0,0,4,0" Foreground="White"/>
                <TextBlock Name="tbDate"  Grid.Column="2" HorizontalAlignment="Right" Width="Auto" Foreground="White">
    				<TextBlock.Text>
    					<Binding StringFormat="{}{0:dd MMM hh:mm tt}" Path="Updated"/>
					</TextBlock.Text>
                </TextBlock>
                <Border BorderBrush="White" BorderThickness="0,0,0,1" Height="2" Background="Black" Opacity="0.295" Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="5" d:LayoutOverrides="GridBox" Visibility="Collapsed"/>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Enclosures.Count}" Value="0">
                    <Setter Property="Visibility" Value="Hidden" TargetName="AttachmentImage"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsReaded}" Value="true">
                    <Setter Property="FontWeight" Value="Normal" TargetName="tbTitle"/>
                    <Setter Property="FontWeight" Value="Normal" TargetName="tbDate"/>
                    <Setter Property="Foreground" Value="{StaticResource ContrastBrush}" TargetName="tbTitle"/>
                    <Setter Property="Foreground" Value="{StaticResource ContrastBrush}" TargetName="tbDate"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>

        <Border Style="{DynamicResource WindowContainerStyle}" Background="{x:Null}" BorderBrush="{x:Null}">

            <Grid x:Name="LayoutRoot">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid Background="{DynamicResource PanelBrush}" Margin="0,-1,0,0">
                    <StackPanel VerticalAlignment="Top" Orientation="Horizontal" Margin="0" Height="34" HorizontalAlignment="Left">
                        <RadioButton x:Name="SourcesRadioButton" Content="Sources" Tag="Sources"  Template="{DynamicResource RadioButtonTemplate}" Foreground="{DynamicResource ContrastBrush}" HorizontalAlignment="Center" Width="82.9" FontWeight="Bold" FontFamily="Segoe WP Semibold" GroupName="RSSView" Margin="10,0,0,0" Checked="RadioButton_Checked" Focusable="False"/>
                        <RadioButton x:Name="FavoritesRadioButton" Content="Favorites" Tag="Favorites" Template="{DynamicResource RadioButtonTemplate}" Foreground="#FFE0E0E0" HorizontalAlignment="Center" Width="82.9" FontWeight="Bold" FontFamily="Segoe WP Semibold" GroupName="RSSView" Checked="RadioButton_Checked" Margin="3,0" Focusable="False"/>
                        <RadioButton x:Name="CategoriesRadioButton" Content="Categories" Tag="Categories" Template="{DynamicResource RadioButtonTemplate}" Foreground="#FFE0E0E0" HorizontalAlignment="Center" Width="82.9" FontWeight="Bold" FontFamily="Segoe WP Semibold" GroupName="RSSView" Checked="RadioButton_Checked" Focusable="False"/>
                        <Rectangle Fill="#FF292929" StrokeThickness="0" Width="1" HorizontalAlignment="Center" Margin="4" Visibility="Collapsed"/>
                        <Border BorderBrush="Black" BorderThickness="1,0,0,0" Width="2" Background="White" Opacity="0.295" CornerRadius="1" Margin="0,4"/>
                        <TextBlock TextWrapping="Wrap" Text="RSS Reader" VerticalAlignment="Center" Foreground="{DynamicResource ContrastBrush}" FontFamily="Segoe WP Semibold" FontSize="16" Margin="7,0,0,1"/>
                    </StackPanel>
                    <Button x:Name="MediaButton" HorizontalAlignment="Right" d:LayoutOverrides="Height" Template="{DynamicResource TransparentFBButtonTemplate}" VerticalAlignment="Center" Width="20" Margin="0,2,34,0" Click="MediaButton_Click">
                        <Image x:Name="MainViewImage" Source="/Feedbook;component/Images/podcast.png"/>
                    </Button>
                    <Border BorderBrush="Black" BorderThickness="1,0,0,0" HorizontalAlignment="Right" Width="2" Background="White" Margin="4,9,27,9" Opacity="0.295" CornerRadius="1"/>
                    <Button Content="Ë" HorizontalAlignment="Right" VerticalAlignment="Center" Template="{DynamicResource TransparentFBButtonTemplate}" Foreground="{DynamicResource ContrastBrush}" FontSize="16" FontWeight="Bold" Margin="0,1,4,0" Cursor="Hand" Click="DiscoveryRSS_Click" FontFamily="Wingdings 2"/>
                </Grid>
                <Border Background="{DynamicResource BackgroundBrush}" Grid.Row="1">
                    <Grid x:Name="RSSGrid" Grid.Row="1">
                        <Grid.Resources>
                            <CollectionViewSource x:Key="FeedViewSource" Source="{Binding SelectedItem.Feeds, ElementName=ChannelListBox}">
                                <CollectionViewSource.SortDescriptions>
                                    <scm:SortDescription Direction="Descending" PropertyName="Updated"/>
                                </CollectionViewSource.SortDescriptions>
                                <CollectionViewSource.GroupDescriptions>
                                    <PropertyGroupDescription Converter="{StaticResource DateTimeToOutlookStyleGroupConverter}" PropertyName="Updated"/>
                                </CollectionViewSource.GroupDescriptions>
                            </CollectionViewSource>
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" MinWidth="197"/>
                            <ColumnDefinition Width="0.43*"/>
                            <ColumnDefinition Width="0.566*"/>
                        </Grid.ColumnDefinitions>
                        <ListBox x:Name="ChannelListBox" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{DynamicResource ContrastBrush}" Margin="13,34,9,34" ItemTemplate="{DynamicResource ChannelTemplate}" ItemContainerStyle="{DynamicResource MyListBoxItem}" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="ChannelListBox_SelectionChanged" HorizontalAlignment="Left" MaxWidth="175"/>
                        <Border BorderBrush="Black" BorderThickness="1,0,0,0" Background="White" Width="1.7" HorizontalAlignment="Right" Padding="0" Margin="0,34,2,34" Opacity="0.35"/>
                        <TextBox Grid.Column="1" x:Name="SeachTextBox" TextChanged="TextBox_TextChanged" VerticalAlignment="Top" Foreground="{DynamicResource ContrastBrush}" CaretBrush="{DynamicResource ContrastBrush}" Padding="4,3,2,2" Margin="4,2,24,0" ToolTip="Search feed"/>
                        <ListBox Grid.Column="1" x:Name="FeedListBox" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{DynamicResource ContrastBrush}" ItemContainerStyle="{DynamicResource MyListBoxItem}" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding Source={StaticResource FeedViewSource}}" ItemTemplate="{DynamicResource FeedTitleTemplate}" Margin="0,26,4,0" 
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="FeedListBox_SelectionChanged" TextSearch.TextPath="TextDescription" >
                            <ListBox.GroupStyle>
                                <StaticResource ResourceKey="OutlookGroupStyle"/>
                            </ListBox.GroupStyle>
                        </ListBox>
                        <GridSplitter Width="5" Grid.Column="1" Background="{DynamicResource PanelBrush}"/>
                        <local:FeedView Grid.Column="2" x:Name="FeedView" DataContext="{Binding ElementName=FeedListBox, Path=SelectedItem}" ButtonBase.Click="FeedView_Click" Visibility="Visible"/>
                        <views:MediaEnclosureView x:Name="MediaEnclosureView" Grid.Column="2" d:LayoutOverrides="GridBox" Margin="0" Visibility="Collapsed"/>
                    </Grid>
                </Border>
                <StackPanel x:Name="DiscoverRSSMessage" Orientation="Horizontal" Grid.Row="1" d:LayoutOverrides="Width" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
                    <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center" Foreground="{DynamicResource ContrastBrush}" Text="Discover RSS feeds from any site ... "/>
                    <Button Content="click here" Template="{DynamicResource TransparentButtonTemplate}" Foreground="{DynamicResource FeedTitleBrush}" d:LayoutOverrides="Height" Cursor="Hand" Click="DiscoveryRSS_Click"/>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>